package itcast.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import itcast.domain.User;
import itcast.service.UserService;
import itcast.service.UserServiceimpl;

/**
 * Servlet implementation class FinduserServlet
 */
@WebServlet("/finduserServlet")
public class FinduserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FinduserServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	//	doGet(request, response);
		//1、设置编码
		request.setCharacterEncoding("utf-8");
		//2、获取id
		String id=request.getParameter("id");
		//3、调用Service查询对象
		UserService service=new UserServiceimpl();
		User user=service.finduserid(id);
		//4、将user存储到update.jsp
		request.setAttribute("user", user);
		request.getRequestDispatcher("update.jsp").forward(request, response);
		
	}

}
